package cm.iccsoft.android.telecomcost.entities;

import java.util.ArrayList;
import android.text.format.*;

public class MonthlyThreshold extends Threshold {

	private Month _month = new Month();
	private double _week1Threshold;
	private double _week2Threshold;
	private double _week3Threshold;
	private double _week4Threshold;
	public static int[] weeksOfMonth = new int[]{1,2,3,4};
	
	public static int PROP_WEEK1 = 1;
	public static int PROP_WEEK2 = 2;
	public static int PROP_WEEK3 = 3;
	public static int PROP_WEEK4 = 4;

	public CharSequence getMonthNameLong() {
		return DateUtils.getMonthString(_month.getMonthOfYear(), DateUtils.LENGTH_LONG);
	}

	public CharSequence getMonthNameShort() {
		return DateUtils.getMonthString(_month.getMonthOfYear(), DateUtils.LENGTH_SHORT);
	}

	public MonthlyThreshold(double d, Month monthOfYear) {
		super(d);
		_month = monthOfYear;
	}

	public MonthlyThreshold() {
	}

	@Override
	public String getType() {
		return "MonthlyThreshold";
	}

	@Override
	public void setType(String type) {

	}

	public void setMonthOfYear(Month monthOfYear) {
		this._month = monthOfYear;
	}

	public Month getMonth() {
		return _month;
	}

	@Override
	public TimePeriod getPeriod() {
		return TimePeriod.MONTH;
	}

	@Override
	public void setPeriod(TimePeriod _period) {
		// do nothing, the period is fixed
	}

	@Override
	public String toString() {
		return _month.toString() + " ( " + getAmount() + " )";
	}

	public void setWeek1Threshold(double _week1Threshold) {
		this._week1Threshold = _week1Threshold;
	}

	public double getWeek1Threshold() {
		return _week1Threshold;
	}

	public void setWeek2Threshold(double _week2Threshold) {
		this._week2Threshold = _week2Threshold;
	}

	public double getWeek2Threshold() {
		return _week2Threshold;
	}

	public void setWeek3Threshold(double _week3Threshold) {
		this._week3Threshold = _week3Threshold;
	}

	public double getWeek3Threshold() {
		return _week3Threshold;
	}

	public void setWeek4Threshold(double _week4Threshold) {
		this._week4Threshold = _week4Threshold;
	}

	public double getWeek4Threshold() {
		return _week4Threshold;
	}

	public static final String PROP_TYPE = "MonthlyThreshold";

	public double getWeekAmount(int weekOfMonth) throws Exception {
		switch (weekOfMonth) {
		case 1:
			return getWeek1Threshold();
		case 2:
			return getWeek2Threshold();
		case 3:
			return getWeek3Threshold();
		case 4:
			return getWeek4Threshold();
		default:
			throw new Exception("invalide week of month..." + weekOfMonth);
		}
	}

	public void setWeekAmount(int weekOfMonth, double amount) throws Exception {
		switch (weekOfMonth) {
		case 1:
			setWeek1Threshold(amount);
			break;
		case 2:
			setWeek2Threshold(amount);
			break;
		case 3:
			setWeek3Threshold(amount);
			break;
		case 4:
			setWeek4Threshold(amount);
			break;
		default:
			throw new Exception("invalide week of month..." + weekOfMonth);
		}
	}

	public String[] getWeeksArrayAdapter() {
		return new String[] { "Week 1 ( " + getWeek1Threshold() + " )",
				"Week 2 ( " + getWeek2Threshold() + " )",
				"Week 3 ( " + getWeek3Threshold() + " )",
				"Week 4 ( " + getWeek4Threshold() + " )" };

	}

	public ArrayList<WeeklyThreshold> getWeeklyThreshold() {
		ArrayList<WeeklyThreshold> thresholds = new ArrayList<WeeklyThreshold>();
		thresholds.add(new WeeklyThreshold(getWeek1Threshold(), 1, getMonth()));
		thresholds.add(new WeeklyThreshold(getWeek2Threshold(), 2, getMonth()));
		thresholds.add(new WeeklyThreshold(getWeek3Threshold(), 3, getMonth()));
		thresholds.add(new WeeklyThreshold(getWeek4Threshold(), 4, getMonth()));
		return thresholds;
	}
}
